package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//@ControllerAdvice + ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(LeaseException.class)
    //处理异常的方法
    public Result resolveLeaseException(LeaseException leaseException) {
        leaseException.printStackTrace();
        return Result.fail(leaseException.getCode(), leaseException.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result resolveException(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }
}
